//
//  BaseTableViewController.m
//  HuLaQuan
//
//  Created by hok on 1/14/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "BaseTableViewController.h"

@implementation BaseTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setNeedsStatusBarAppearanceUpdate];
    
    self.tableView.backgroundColor = UIColorFromRGBA(kBackgroundColor, 1.0);

    self.view.backgroundColor = UIColorFromRGBA(kBackgroundColor, 1.0);
    
    [self initData];
    
    [self setupUI];
}
- (void)setupUI
{
    
}
- (void)initData
{
    
}


- (void)setupTapGesture
{
    UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelGenericTapView:)];
    tapRec.delegate = self;
    self.tapGesture = tapRec;
    [self.view addGestureRecognizer:self.tapGesture];
}
- (void)handelGenericTapView:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
    {
        // handling code
        // [self.view endEditing:YES];
        [[UIApplication sharedApplication].keyWindow endEditing:YES];
    }
}
/**
 *  Setup Navigation Back Button
 */

- (void)setupNavBackButton
{
    UIImage* img1=[[UIImage imageNamed:@"back.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem*barItem1 = [[UIBarButtonItem alloc]
                                initWithImage:img1
                                style:UIBarButtonItemStylePlain
                                target:self
                                action:@selector(goBackAction)];
    self.navigationItem.leftBarButtonItem = barItem1;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)setupFooterForTableView
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,1)];
    self.tableView.tableFooterView = v;
}
- (void)goBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

/*********** 新增 ***********/
- (void)createNavigationBarRightBarButtonItemWithTitle:(NSString *)title {
    [self createNavigationBarRightBarButtonItemWithTitle:title style:UIBarButtonItemStylePlain];
}

/*********** 新增 ***********/
- (void)createNavigationBarRightBarButtonItemWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style {
    [self createNavigationBarRightBarButtonItemWithTitle:title style:style target:self action:@selector(rightAction)];
}

/*********** 新增 ***********/
- (void)createNavigationBarRightBarButtonItemWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    //这个可以简单的理解为特殊的按钮，不需要我们去考虑布局，只要实现样式和内容，系统为我们进行布局。
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [button setTintColor:[UIColor whiteColor]];
    [button setTitle:title forState:UIControlStateNormal];
     button.titleLabel.font = [UIFont fontWithName:FONT_NAME size:14];
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithCustomView:button];;
    self.navigationItem.rightBarButtonItem = right;
}

- (void)rightAction {
    //我们只实现框架，不实现内容，主要是为了消除警告
}
- (void)showNetWorkError:(id)error
{
    if ([error isKindOfClass:[NSError class]]) {
        [self.view makeToast:TEXT_SERVER_NOT_RESPOND];
    }
    if ([error isKindOfClass:[NSString class]]) {
        [self.view makeToast:error];
    }
}

- (NSString *) cardType:(NSString *)typeString
{
    return [[typeString substringFromIndex:typeString.length - 5] isEqualToString:@"DEBIT"] ? @"储蓄卡" : @"信用卡";
}
@end
